import cv2
from PIL import Image

def img_capture(video):
	cap=cv2.VideoCapture(video)#创建视频工程
	num=0
	ret,frame=cap.read()
	while ret:#循环保存帧
		if num % 3 ==0:#3 frame/s
			cv2.imwrite("img%d.png" % num, frame)#保存
			print("[I] Get %d Frame!" % num)
		if num>1080:#1080帧数
			print("[I] Save Done!\n")
			break
		ret, frame=cap.read()
		num+=1#等同于num=num+1

ascii_char=list("$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<>i!lI;:,\"^`'.")

def ptc(num):
	print("[I] Turning...")
	cvideo = open("chr_video.txt","w")
	for i in range(0,num,3):
		im = Image.open("img%d.png" % i,"r")#打开图像
		im = im.convert("L").resize([96,54])#调整大小
		for y in range(54):
			for x in range(96):
				char = int(im.getpixel((x,y)) /256 * len(ascii_char))
				cvideo.write(ascii_char[char] + " ")
			cvideo.write("\n")
		print("[I] %d Turn Done!" % i)
	cvideo.close()
	print("[I] Turn Done!")

img_capture("8.mp4")
ptc(1080)
exit=input("[I] Done!")